// import { Blog } from "src/blog/entities/blog.entity";
// import { Like } from "src/like/entities/like.entity";
import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { UnsignedInt, utcToBeijing } from '../../utils';
import { Like } from '../../like/entities/like.entity';
import { Blog } from '../../blog/entities/blog.entity';
import { Daily } from '../../daily/entities/daily.entity';
@Entity()
export class Comment {
  @PrimaryGeneratedColumn()
  id: number;

  @CreateDateColumn({
    type: 'timestamp',
    transformer: {
      to(value: Date): number {
        return value ? value.getTime() : null;
      },
      from(value: number) {
        // 将UTC时间转换为北京时间
        return utcToBeijing(value);
      },
    },
  })
  createDate: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    transformer: {
      to(value: Date): number {
        return value ? value.getTime() : null;
      },
      from(value: number) {
        // 将UTC时间转换为北京时间
        return utcToBeijing(value);
      },
    },
  })
  updateDate: Date;

  @Column({
    comment: '评论类型 0文章 1说说 2图片',
    default: 0,
  })
  type: number;

  @Column({
    comment: '评论内容',
    length: 500,
  })
  content: string;

  // @Column({
  //   comment: '文章id'
  // })
  // blogId: number

  @Column({
    comment: '业务id',
  })
  createId: number;

  @Column({
    comment: '用户id',
    nullable: true
  })
  userId: number;

  @Column({
    comment: '用户名',
    nullable: true
  })
  username: string;

  @Column({
    comment: '父id',
    nullable: true,
  })
  parentId: number;

  @Column({
    comment: '回复 0否1是',
    default: 0,
  })
  reply: number;

  @Column({
    comment: '回复谁',
    nullable: true,
  })
  menberId: string;

  @Column({
    comment: '头像',
    nullable: true
  })
  avatar: string;

  @Column({
    type: 'int',
    unsigned: true,
    comment: '点赞数',
    default: 0,
  })
  like: UnsignedInt;

  @Column({
    comment: '评论的图片',
    nullable: true,
  })
  commentPic: string;

  @Column({
    comment: '点赞',
    default: 0,
  })
  action: 0 | 1;

  @Column({
    comment: 'ip',
    nullable: true,
  })
  ip: string;

  @Column({
    comment: '博客id',
    nullable: true
  })
  blogId: number;

  @Column({
    comment: '说说id',
    nullable: true
  })
  dailyId: number;

  @ManyToOne(() => Blog, (blog) => blog.comments)
  blog: Blog[];

  @OneToMany(() => Like, (like) => like.comment)
  likes: Like[];

  @ManyToOne(() => Daily, daily=>daily.comments)
  daily: Daily[]
}
